package com.itheima.test2;

public class StringDemo3 {
    public static void main(String[] args) {
        // 字符串反转
        String str = reverse("abcd");
        System.out.println(str);
    }

    public static String reverse(String str) {

        // 遍历字符串，拼接返回
        // 需要从后向前遍历
        String result = "";
        for (int i = str.length() - 1; i >= 0; i--) {
            char c = str.charAt(i);
            result = result + c;
        }

        return result;
    }


}
